package com.zxy.locationtest2;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

public class Client {
	public static String GET_LATLOG = "http://zynet.3322.org/lal.php";
	
	public static String GET_LATLOG1 = "http://www.517hanghai.com/test/zxy/ok.php";
	public static String GET_LATLOG2 = "http://www.517hanghai.com/test/zxy/err.php";

	public static String sendPost(String url, List<NameValuePair> params) {
		String msg = "";
		HttpClient httpClient = new DefaultHttpClient();
		HttpPost post = new HttpPost(url);
		try {
			post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
			HttpResponse response = httpClient.execute(post);
			int code = response.getStatusLine().getStatusCode();
			if (code == 200) {
				msg = EntityUtils.toString(response.getEntity());
			} else {
				msg = "code:" + code;
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			msg = e.toString();
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			msg = e.toString();
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			msg = e.toString();
			e.printStackTrace();
		}
		return msg;

	}
}
